import Vue from 'vue';
import preview from './src/image-preview.vue';
let messageInstance: any = null;
const PreviewConstructor = Vue.extend(preview);

const init = (options) => {
  messageInstance = new PreviewConstructor({
    propsData: options
  });
  messageInstance.$mount();
  document.body.appendChild(messageInstance.$el);
  return {
    then (fn) {
      messageInstance.callback = (action, value) => {
        fn({ action, value })
      };
    }
  }
};

const caller = (options) => {
  return init(options);
};

export default {
  // 返回 install 函数 用于 Vue.use 注册
  install (vue) {
    vue.prototype.$ImgPrview = caller;
  }
};
